package com.jianda.view;

import com.jianda.service.ActionListenerService;
import com.sun.glass.events.KeyEvent;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;

/**
 * 菜单编辑类
 */
public class MenuView {

    public static void editMenu(JFrame frame) {
        System.out.println("getHeight/Menu" + frame.getHeight());
        System.out.println("getWidth/Menu" + frame.getWidth());
        JMenuBar menuBar = new JMenuBar();
        frame.setJMenuBar(menuBar);

        //创建并添加各菜单，注意：菜单的快捷键是同时按下Alt键和字母键，方法setMnemonic('F')是设置快捷键为Alt +Ｆ
       // JMenu menuFile = new JMenu("文件(F)"), menuEdit = new JMenu("编辑(E)"), menuView = new JMenu("查看(V)");
       /* menuFile.setMnemonic('F');
        menuEdit.setMnemonic('E');
        menuView.setMnemonic('V');
        menuBar.add(menuFile);
        menuBar.add(menuEdit);
        menuBar.add(menuView);

        //添加“文件”菜单的各菜单项
        JMenu itemOpen = new JMenu("打开");
        itemOpen.setMnemonic('O');
        JMenuItem itemOpen1 = new JMenuItem("打开x");
        JMenuItem itemOpen2 = new JMenuItem("打开y");
        itemOpen.add(itemOpen1);
        itemOpen.add(itemOpen2);
        JMenuItem itemSave = new JMenuItem("保存");
        itemSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
        menuFile.add(itemOpen);
        menuFile.add(itemSave);*/

        // 添加“编辑”菜单的各菜单项
        JMenu menuEdit = new JMenu("设置(E)");
        // 添加快捷键 alt+e
        menuEdit.setMnemonic('E');
        JMenuItem itemSet = new JMenuItem("设置串口参数");
        itemSet.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
        // 添加事件
        addIncident(itemSet);
        // 添加子菜单
        menuEdit.add(itemSet);
        menuBar.add(menuEdit);
}

    private static void addIncident(JMenuItem itemSet) {
        itemSet.addActionListener(new ActionListenerService());
    }
}
